package leetcode.tree;

import leetcode.tree.common.TreeNode;

/**
 * @author mazouri
 * @create 2021-09-27 22:56
 */
public class _1448_goodNodes {
    int count = 0;

    public int goodNodes(TreeNode root) {
        int max  = root.val;
        dfs(root,max);
        return count;
    }

    private void dfs(TreeNode root,int max) {
        if (root == null) return;

        if (root.val >= max) {
            count++;
            max = root.val;
        }

        dfs(root.left,max);
        dfs(root.right,max);
    }
}
